/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package main;

import aso.upna.playlist.GenericList;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author triki
 */
public class DirHandler {

    private String path_base;

    public DirHandler(String path)
    {
        path_base = new String(path);
        File f = new File(path);
        if(!f.exists())
            f.mkdir();
    }

    public boolean writeOnFile(GenericList l,String filename)
    {
        try 
        {
            FileOutputStream of = null;
            ObjectOutputStream os = null;
            File f = new File(path_base + filename);
            if (f.exists()) {
                return false;
            }

            of = new FileOutputStream(f);
            os = new ObjectOutputStream(of);

            os.writeObject(l);

            return true;
        }
        catch (IOException ex)
        {
            return false;
        }
    }

    public boolean deleteFile(String filename)
    {
         File f = new File(path_base + filename);
         if(f.exists())
         {
             f.delete();
             return true;
         }
         return false;
    }

    public boolean deleteFile(String file,String ext)
    {
         File f = new File(path_base +file+ext);
         if(f.exists())
         {
             System.out.println("** Eliminando informacion de: "+file);
             f.delete();
             return true;
         }
         return false;
    }
}
